function indmat=loadtransgio( opath, dist, lcone, lctwo ,indp , lbnd , ubnd , cofname ); 
% =========================================================================
% LOADTRANSGIO.M 
%
% function indmat=loadtransgio( opath, dist, lcone, lctwo ,indp , lbnd , ubnd , cofname ); 
% This is a mixture between LOADTRANSNEW and LOADTRANS_TIGHT 
% From the former, preserves the type 2 transformation for the G, IG1, IG2 
% From the latter, slightly tightens the intervals, by 1e-5, of the other
% distributions to prevent initialization problems or out of bound
% coefficients 
% Syntaxis is identical to LOADTRANS_TIGHT 
% 
% Function must be called with the complete dist, lcone and lctwo vectors,
% i.e. including for the calibrated variables 
% 
% Alejandro Justiniano 11/16/2005 
% =======================================================================
nump = length( cofname ); 
temp = [length(dist); length(lcone); length(lbnd); length(ubnd) ]; 
if any( temp~= nump ) == 1 
    error('Wrong dimension inputs in LOADTRANSGIO.M') 
end 

% Create indmat matrix 
indmat=zeros(nump,4);

jj=1;
for jj=1:nump;
    
    cdist=deblank(upper(dist(jj)));
    
    if strcmp( cdist ,'B' ) == 1 
        
        indmat(jj,1)=1;
        indmat(jj,2)=max( 1e-4 , lbnd(jj)  ) ;
        indmat(jj,3)=min( 0.99 ,  ubnd(jj)  ) ; 
        indmat(jj,4)=1;
        
    elseif ( strcmp( cdist , 'N' ) == 1 | strcmp( cdist, 'U' ) == 1 ) 
        
        indmat(jj,1)=1;
        indmat(jj,2)=lbnd(jj)+0.0001;
        indmat(jj,3)=ubnd(jj)-0.0001;
        indmat(jj,4)=1;
        
    elseif strcmp( cdist , 'C' ) == 1 
        
        indmat(jj,1)=0;
        indmat(jj,2)=lcone(jj,1);
        indmat(jj,3)=0;
        indmat(jj,4)=1;
        
    elseif ( strcmp(cdist,'G')==1 | strcmp(cdist,'W') ==1 | strcmp(cdist,'I') == 1 );
        indmat(jj,1)=2;
        indmat(jj,2)=1e-4;
        indmat(jj,3)=0;
        indmat(jj,4)=1;
        
    else;
        
        error('No distrubtion recognized');

    end
end
       
% Check all parameters to be estimated have a transformation 
chh1=find( indmat(indp,1) ~=1 & indmat(indp,1) ~= 2 ) ; 
if sum(chh1) > 0; 
    chh1 
    error('Need assign a transformation for parameter to be estimated')
end

% Check all calibrated parameters do not have a transformation 
ch = find( lctwo == 0 ); 
if any( indmat(ch,1) ~= 0 ); 
    error('Calibrated parameters have been assigned a 0,1 transformation') 
end 


% Checked all transformed parameters have a minimum interval length 
indint=find( indmat(:,1) == 1); 
chh=abs ( indmat(indint,2) - indmat(indint,3) ); 
chh2=find( chh < 0.1 ); 
if sum(chh2) > 0;
    chh2
    warning('Small interval in the transformation of a coefficient' )
    inp=input( 'Wish to Proceed? (Y/N)','s');    
    if upper(inp)=='N'
        error(' End Run') 
    end
end 


% Print the transformation matrix 
temp_cell1 = num2cprec( indmat(:,1) , 1 ); 
temp_cell2 = num2cprec( indmat(:,2:end), 4 ); 
temp_cell  = [cofname temp_cell1 temp_cell2]; 
disp('Transformation matrix from LOADTRANSGIO.M' ) 
printcell( temp_cell ); 


